package com.info.provider.service.aliyun.oos;

import com.aliyun.oss.OSSClient;

import java.io.File;

/**
 * Created by pengshuo on 2018/4/11 15:36
 * Description:
 * Modified By:
 * Version:
 *
 * @author pengshuo
 */
public class Chapter1 {

    public static void main(String[] args) {
        String endpoint = "oss-cn-shanghai.aliyuncs.com";
        // 云账号AccessKey有所有API访问权限，建议遵循阿里云安全最佳实践，创建并使用RAM子账号进行API访问或日常运维
        String accessKeyId = "LTAIZxmOpRul6ihH";
        String accessKeySecret = "b5tyO0wp0LSgUwg7ZvLN9j6Vwpp5hC";
        // 创建OSSClient实例
        OSSClient client = new OSSClient(endpoint, accessKeyId, accessKeySecret);

        // 判断 文件是否存在
        System.out.println(client.doesObjectExist("springmars", "wechat/check_blue.png"));

        // 上传文件
        File file = new File("C:\\Users\\speng\\Desktop\\情侣头像\\情侣2-a.jpg");

        System.out.println(client.putObject("springmars","wechat/20180411/情侣2-a.jpg",file).getETag());

        // 删除文件
        client.deleteObject("springmars","wechat/20180411/情侣2-b.jpg");

        client.shutdown();
    }
}
